package com.ethank.enums;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ethank.entity.VoucherResponseVO;
import com.ethank.enums.ali.TrainTicketEnum;

import java.lang.reflect.Method;
import java.util.*;

/**
 * @author Administrator
 */
public enum BillEnum {
    MIXED_INVOICES(0, "HTBill", "混贴发票", ""),
    INVOICE(1, "recognizeInvoice", "增值税发票", "InvoiceFieldEnum"),
    COMMON_PRINTED_INVOICE(3, "commonPrintedInvoice", "通用机打发票", "CommonPrintedInvoiceEnum"),
    QUOTA_INVOICE(5, "quotaInvoice", "定额发票", "QuotaInvoiceEnum"),
    TAXI_INVOICE(7, "taxiInvoice", "出租车票", "InvoiceAndTaxiEnum"),
    TRAIN_INVOICE(8, "trainInvoice", "火车票", "TrainTicketEnum")
    , TOLL_INVOICE(9, "tollInvoice", "过路过桥费发票", "TollInvoiceEnum"),
    BUS_SHIP_TICKET(10, "busShipTicket", "客运车船票", "BusShipTicketEnum"),
    // AIR_ITINERARY(14, "airItinerary", "航空行程单"),
    AIR_ITINERARY(14, "airItinerary", "机票行程单", "AirItineraryEnum"),
    ROLL_TICKET(16, "rollTicket", "增值税发票卷票", ""), /*PAYMENT_RECORD
    (20, "paymentRecord", "支付详情"),
    RIDE_HAILING_ITINERARY(21, "rideHailingItinerary", "网约车行程单"),*/
    ROLL_OIL_TICKET(16, "rollTicket", "卷票", "RollTicketBillEnum");


    private Integer type;
    private String invokeName;
    private String billTypeName;

    private String tableName;


    BillEnum(Integer type, String invokeName, String billTypeName, String tableName) {
        this.type = type;
        this.invokeName = invokeName;
        this.billTypeName = billTypeName;
        this.tableName = tableName;
    }

    BillEnum() {
    }

    public static ArrayList<HashMap<String, Object>> getBills() {
        ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
        for (BillEnum be : values()) {
            if (be.type == 0) {
                continue;
            }
            HashMap<String, Object> resultMap = new HashMap<>();
            resultMap.put("label", be.billTypeName);
            resultMap.put("value", be.type);
            // 映射到对应的
            try {
                Class<?> clazz = Class.forName("com.ethank.enums.ali."+be.getTableName());
                // 创建类的实例
                Object[] enumConstants = clazz.getEnumConstants();
                for (Object trainTicketEnum : enumConstants) {
                    Method valueMethod = clazz.getMethod("convertVoucher");
                    Object obj = valueMethod.invoke(trainTicketEnum);
                    resultMap.put("records", obj);
                }

            } catch (Exception e) {
                e.getMessage();
            }
            resultList.add(resultMap);
        }
        return resultList;
    }

    public static Integer getTypeByBillTypeName(String byn) {
        if (byn == null || byn.isEmpty()) {
            return null;
        }
        for (BillEnum value : BillEnum.values()) {
            if (value.billTypeName.equals(byn)) {
                return value.type;
            }
        }
        return null;
    }

    /**
     * @param type
     * @return
     * @desc 根据类型查询相应的方法
     */
    public static String getInvokeName(Integer type) {
        String invokeName = "";
        if (null == type) {
            return invokeName;
        }
        for (BillEnum billEnum : BillEnum.values()) {
            if (billEnum.getType().equals(type)) {
                return billEnum.getInvokeName();
            }
        }

        return invokeName;
    }

    /**
     * @Description: 根据类型查询对应的类型名称
     * @Param: [type]
     * @return: java.lang.String
     * @Author: tf
     * @Date: 2024-03-05
     */
    public static String getBillTypeName(Integer type) {
        String billTypeName = "";
        if (null == type) {
            return billTypeName;
        }
        for (BillEnum billEnum : BillEnum.values()) {
            if (billEnum.getType().equals(type)) {
                return billEnum.getBillTypeName();
            }
        }
        return billTypeName;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getBillTypeName() {
        return billTypeName;
    }

    public void setBillTypeName(String billTypeName) {
        this.billTypeName = billTypeName;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getInvokeName() {
        return invokeName;
    }

    public void setInvokeName(String invokeName) {
        this.invokeName = invokeName;
    }
}
